<?php
namespace Admin\Controller;
use Think\Controller;
class LoginController extends Controller {

    public function login(){
        if(isset($_SESSION['user_name'])){
            $this->success('你已经登录',U('Admin/Index/index'),2);
        }else{
            if (isset($_POST['user_name'])){
            $admin = M('admin')->select();
                $verify = I('verify');
                if(!check_verify($verify)){
                    $this->error("亲，验证码输错了哦！",$this->site_url,2);
                }
                for ($i  = 0 ;$i <= count($admin)-1;$i++){
                    if (I('user_name') == $admin[$i]['user_name']&&MD5(I('pwd')) == $admin[$i]['password']){
                        $user_name = I('user_name');
                        session('user_name',$user_name);
                        $this->redirect('/Admin/Index/index','登录成功',1);
                    }

                }
           }
            $this->display();
        }
    }

    public function quit(){
        unset($_SESSION['user_name']);
        session_destroy();
            $this->success('退出成功',U('Admin/Login/login'),2);


}

    public function verify_c(){
        $Verify = new \Think\Verify();
        $Verify->fontSize = 18;
        $Verify->length   = 4;
        $Verify->useNoise = false;
        $Verify->codeSet = '0123456789';
        $Verify->imageW = 130;
        $Verify->imageH = 40;
        $Verify->useImgBg = true;
        //$Verify->expire = 600;
        $Verify->entry();
    }

}